﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace Derbster.Domain
{
    [ContractClass(typeof(SkaterRepositoryContracts))]
    public interface ISkaterRepository : IQueryable<Skater>
    {
        Skater Create(string name, string number);
        Skater FindById(int skaterId);
        Skater FindByName(string skaterName);
        Skater Update(Skater skater);
        void Delete(Skater skater);
    }

    [ContractClassFor(typeof(ISkaterRepository))]
    public abstract class SkaterRepositoryContracts : ISkaterRepository
    {
        public IEnumerator<Skater> GetEnumerator()
        {
            throw new NotImplementedException();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        public Expression Expression
        {
            get
            {
                throw new NotImplementedException();
            }
        }

        public Type ElementType
        {
            get
            {
                throw new NotImplementedException();
            }
        }

        public IQueryProvider Provider
        {
            get
            {
                throw new NotImplementedException();
            }
        }

        public Skater Create(string name, string number)
        {
            Contract.Requires(!string.IsNullOrWhiteSpace(name));
            Contract.Requires(!string.IsNullOrWhiteSpace(number) && number.Length <= 4);
            Contract.Requires(Regex.IsMatch(number, "[a-zA-Z0-9]+"));
            Contract.Ensures(Contract.Result<Skater>().SkaterId > 0);

            return null;
        }

        public Skater FindById(int skaterId)
        {
            Contract.Requires(skaterId > 0);
            return null;
        }

        public Skater FindByName(string skaterName)
        {
            Contract.Requires(!String.IsNullOrWhiteSpace(skaterName));
            return null;
        }

        public Skater Update(Skater skater)
        {
            Contract.Requires(skater != null);
            Contract.Requires(skater.SkaterId > 0);
            return null;
        }

        public void Delete(Skater skater)
        {
            Contract.Requires(skater != null);
            Contract.Requires(skater.SkaterId > 0);
        }
    }
}
